home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#49 (Oct 89)
/
Driver Code
/
RespondToRead.a
< prev
next >
Wrap
Text File
|
1988-01-06
|
3KB
|
136 lines
TITLE 'Respond to completed read from pump'
BLANKS ON
CASE ON
String Pascal
Machine MC68020
PRINT OFF
INCLUDE 'Traps.a'
INCLUDE 'ToolEqu.a'
INCLUDE 'QuickEqu.a'
INCLUDE 'SysEqu.a'
INCLUDE 'SysErr.a'
INCLUDE 'Quickdraw.inc'
INCLUDE 'TimeEqu.a'
INCLUDE 'PumpErrs.inc'
LOAD 'ProgStrucMacs.d'
LOAD 'FlowCtlMacs.d'
PRINT ON
ActionOffset equ csParam
RequestOffset equ csParam+2
InfoOffset equ csParam+4
IntegerFmt equ 0
HexFmt equ 1
Ask equ 0
Set equ 1
DStore Record 0
WriteUnit DS.W 1
ReadUnit DS.W 1
TimeCount DS.L 1
KillBlock DS.L 1
KillTask DS.L 1
IncomingLength DS.B 1
IncomingString DS.B 9
Align 2
TableOffset equ *
TableLen DS.W 1
Table DS.W 5
ENDR
Export Procedure RespondToRead
Begin Save=D0-D3,With=(DStore)
MOVE.B IncomingString(A4),D0
* Exclude pump misreads
If# D0 EQ.B #'!' Then.S
MOVE.W #PumpMisread,ioResult(A3)
Return
EndIf#
* Figure out which (if any) of the pump requests we have.
For# D1 = TableLen(A4) DownTo #0 Until Table(A4,D1.W*2) EQ.B D0 Do.S
EndF#
If# D1 LT.W #0 Then.S
MOVE.W #PumpUnknownRequest,ioResult(A3)
Return
EndIf#
MOVE.W D1,RequestOffset(A3)
* Figure out what the action was
If# IncomingString+1(A4) EQ.B #'=' Then.S
MOVE.W #Set,ActionOffset(A3)
ElseIf#.S IncomingString+1(A4) EQ.B #'?' Then.S
MOVE.W #Ask,ActionOffset(A3)
Else#.S
MOVE.W #PumpUnknownAction,ioResult(A3)
Return
EndIf#
* Calculate the number of remaining characters to be decoded
MOVE.B IncomingLength(A4),D2
EXT.W D2
SUBQ.W #2,D2
LEA IncomingString+2(A4),A0
* Figure out if the request is integer or hex format, and decode the info
If# Table+1(A4,D1.W*2) EQ.B #IntegerFmt Then.S
CLR.W D1
For# D2 DownTo #1 Do.S
MOVE.B (A0)+,D0
SUB.B #'0',D0
If# MI OR D0 GT.B #9 Then.S
MOVE.W #PumpUndecodableNumber,ioResult(A3)
Return
EndIf#
EXT.W D0
MULU.W #10,D1
ADD.W D0,D1
EndF#
Else#.S
For# D2 DownTo #1 Do.S
MOVE.B (A0)+,D0
EXT.W D0
MOVE.W D0,D3
Switch# D0
Case#.S '0'..'9'
SUB.B #'0',D3
Leave#.S
Case#.S 'A'..'F'
SUB.B #'A'-10,D3
Leave#.S
Default#
MOVE.W #PumpUndecodableNumber,ioResult(A3)
Return
EndS#
LSL.W #4,D1
ADD.W D3,D1
EndF#
EndIf#
MOVE.W D1,InfoOffset(A3)
MOVE.W #noErr,ioResult(A3)
Return
ENDP
END